fix(dicom): reject chunks that do not fit the volume buffer - #931
Merged
Conversation
✅ Deploy Preview for volview-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
PaulHax
force-pushed
the
dicom-chunk-dimension-mismatch
branch
from
August 27, 2026 23:02
bb65efa to
9d675f1
Compare
A series whose instances disagree on Rows, Columns, or SamplesPerPixel is still grouped into one volume, whose buffer is sized from the first instance. An instance that decoded larger than its slot threw "RangeError: offset is out of bounds" from TypedArray.set, naming neither the file nor what was wrong with it. One that decoded smaller wrote inside the buffer and raised nothing at all, leaving a frame smeared across a larger slot. Validate each decoded chunk against its slot before writing, and name the file and both sizes in the error. Rejecting a chunk also has to leave the image usable. An errored chunk is now terminal: an image settles, and stops reporting itself as loading, once every chunk is either loaded or errored, so the views drop their progress indicator and auto window/level is computed from the chunks that did load. An image whose every chunk errored settles but stays incomplete, since it holds no pixel data.
PaulHax
force-pushed
the
dicom-chunk-dimension-mismatch
branch
from
August 27, 2026 23:04
9d675f1 to
7c72b1c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A series whose instances disagree on Rows, Columns, or SamplesPerPixel is still
grouped into one volume, and that volume's buffer is sized from the first
instance. Each decoded chunk was written into a slot computed from the series
dimensions, with no check that it fit.
An instance decoding larger than its slot made
TypedArray.prototype.setthrowRangeError: offset is out of bounds, naming neither the file nor what waswrong with it. An instance decoding smaller wrote entirely inside the buffer and
raised nothing at all: the frame is smeared across the top of a larger slot,
silently. The silent case is the more serious one.
The guard already in place covered only a multi-frame instance inside a
multi-file series.
Change
dicomChunkImage.tscomputes the slot each chunk may occupy, one frame perchunk in a multi-file volume and the full depth for a lone multi-frame chunk,
and validates the decoded chunk's width, height, frame count, and component
count against it before writing:
Files are identified by SOP Instance UID, since chunks carry no filename or
source URI. The closing advice is omitted for single-file volumes, where it is
meaningless. Only the offending instance is rejected.
One supporting fix, needed to make a rejection survivable:
A rejected chunk no longer wedges the loading state.
computeStatustreatedanything but
Loadedas still coming, so an errored chunk left the imageincompletewithloadingnever cleared: progress indicators ran forever andimage-statsnever computed auto window/level.Erroredis now terminal. Animage settles once every chunk is
LoadedorErrored, and settling clearsloading. Status reachescompleteonly if at least one chunk loaded, so avolume where everything was rejected settles without claiming to be a finished
image. Auto window/level then computes from the chunks that did load.
Scope
This contains the damage; it does not make heterogeneous series display
correctly. A rejected instance leaves its slot zeroed, so a scout in an axial
stack becomes a blank slice plus one named error rather than a volume of its
own. There is no benign case being preserved: the buffer is sized from the
first instance and the write is a raw copy into a fixed-size slot, so a
differing instance is either a RangeError, a smear, or transposed garbage.
The final solution is to partition on pixel geometry during categorize, as a
sibling of
SeparateOnImageOrientation, so the mismatched instances becometheir own volume and this guard never fires. That is a separate change: it
needs the itk-wasm build and it changes volume IDs, which appear in saved state
files. This guard is still worth keeping afterwards, because grouping and
allocation read metadata tags while the guard compares the size ITK actually
decoded, so a file whose tags disagree with its pixel data is caught here and
nowhere else.